package com.foryou.wechat.controller;

import com.foryou.wechat.common.Constants;
import com.foryou.wechat.model.dto.InviteInfoDTO;
import com.foryou.wechat.service.InviteInfoService;
import com.foryou.wechat.utils.HttpContextUtils;
import com.foryou.wechat.utils.Response;
import com.foryou.wechat.utils.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Lee.
 */
@RestController
@RequestMapping("/v/invite")
public class InviteController {

    private final InviteInfoService inviteInfoService;

    public InviteController(InviteInfoService inviteInfoService) {
        this.inviteInfoService = inviteInfoService;
    }

    @PostMapping("/addWorksInviteInfo")
    public Response addWorksInviteInfo(@RequestBody InviteInfoDTO inviteInfoDTO) {
        ValidatorUtils.validateEntity(inviteInfoDTO);
        if (inviteInfoService.addWorksInviteInfo(inviteInfoDTO) > 0) {
            return Response.success();
        }
        return Response.failure(Constants.OPERATION_FAILURE);
    }

    @PostMapping("/addShootInviteInfo")
    public Response addShootInviteInfo(@RequestBody InviteInfoDTO inviteInfoDTO) {
        if (inviteInfoService.addShootInviteInfo(inviteInfoDTO) > 0) {
            return Response.success();
        }
        return Response.failure(Constants.OPERATION_FAILURE);
    }

    @GetMapping("/getInviteInfoDetail")
    public Response getInviteInfoDetail(@RequestParam Long inviteId) {
        return inviteInfoService.getInviteInfoDetail(inviteId);
    }

    @GetMapping("/findInviteListForReceiveUser")
    public Response findInviteListForReceiveUser(@RequestParam(defaultValue = "0") int start) {
        Long userId = HttpContextUtils.getUserId();
        return inviteInfoService.findInviteListForReceiveUser(start, userId);
    }

    @GetMapping("/findInviteListForSendUser")
    public Response findInviteListForSendUser(@RequestParam(defaultValue = "0") int start) {
        Long userId = HttpContextUtils.getUserId();
        return inviteInfoService.findInviteListForSendUser(start, userId);
    }

}
